home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / w00w00 / sectools / dsniff / decode_yppasswd.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-17  |  2.0 KB  |  96 lines

  1. /*
  2.   decode_yppasswd.c
  3.  
  4.   RPC yppasswd.
  5.  
  6.   Totally untested, i don't run YP. Let me know if this works. :-)
  7.  
  8.   Copyright (c) 2000 Dug Song <dugsong@monkey.org>
  9.  
  10.   $Id: decode_yppasswd.c,v 1.2 2000/05/17 08:12:56 dugsong Exp $
  11. */
  12.  
  13. #include <sys/types.h>
  14. #include <sys/param.h>
  15. #include <rpc/rpc.h>
  16. #include <rpcsvc/yppasswd.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include "rpc.h"
  21. #include "decode.h"
  22.  
  23. /* XXX - <rpcsvc/yppasswd.x> varies on different systems :-( */
  24.  
  25. struct my_passwd {
  26.     char   *pw_name;
  27.     char   *pw_passwd;
  28.     int    pw_uid;
  29.     int    pw_gid;
  30.     char   *pw_gecos;
  31.     char   *pw_dir;
  32.     char   *pw_shell;
  33. };
  34.  
  35. struct my_yppasswd {
  36.     char   *oldpass;
  37.     struct my_passwd newpw;
  38. };
  39.  
  40. static bool_t
  41. xdr_my_passwd(XDR *xdrs, struct my_passwd *objp)
  42. {
  43.     if (xdr_string(xdrs, &objp->pw_name, ~0) &&
  44.         xdr_string(xdrs, &objp->pw_passwd, ~0) &&
  45.         xdr_int(xdrs, &objp->pw_uid) &&
  46.         xdr_int(xdrs, &objp->pw_gid) &&
  47.         xdr_string(xdrs, &objp->pw_gecos, ~0) &&
  48.         xdr_string(xdrs, &objp->pw_dir, ~0) &&
  49.         xdr_string(xdrs, &objp->pw_shell, ~0))
  50.         return (TRUE);
  51.  
  52.     return (FALSE);
  53. }
  54.  
  55. static bool_t
  56. xdr_my_yppasswd(XDR *xdrs, struct my_yppasswd *objp)
  57. {
  58.     if (xdr_string(xdrs, &objp->oldpass, ~0) &&
  59.         xdr_my_passwd(xdrs, &objp->newpw))
  60.         return (TRUE);
  61.     
  62.     return (FALSE);
  63. }
  64.  
  65. int
  66. decode_yppasswd(u_char *buf, int len)
  67. {
  68.     struct rpc_msg msg;
  69.     struct my_yppasswd yp;
  70.     XDR xdrs;
  71.     int hdrlen;
  72.     
  73.     memset(&msg, 0, sizeof(msg));
  74.     
  75.     if ((hdrlen = rpc_decode(buf, len, &msg)) == 0)
  76.         return (0);
  77.     
  78.     if (msg.rm_direction == CALL &&
  79.         msg.rm_call.cb_prog == YPPASSWDPROG &&
  80.         msg.rm_call.cb_proc == YPPASSWDPROC_UPDATE) {
  81.         xdrmem_create(&xdrs, buf + hdrlen, len - hdrlen, XDR_DECODE);
  82.         if (!xdr_my_yppasswd(&xdrs, &yp)) {
  83.             xdr_destroy(&xdrs);
  84.             return (0);
  85.         }
  86.         snprintf(Buf, sizeof(Buf),
  87.              "%s\n%s:%s:%d:%d:%s:%s:%s\n",
  88.              yp.oldpass, yp.newpw.pw_name, yp.newpw.pw_passwd,
  89.              yp.newpw.pw_uid, yp.newpw.pw_gid, yp.newpw.pw_gecos,
  90.              yp.newpw.pw_dir, yp.newpw.pw_shell);
  91.         
  92.         return (strlen(Buf));
  93.     }
  94.     return (0);
  95. }
  96.